package com.freeman.cement.controller;

import com.freeman.cement.annotation.NeedRole;
import com.freeman.cement.entity.MyEvent;
import com.freeman.cement.entity.ResponseResult;
import com.freeman.cement.service.EventDataService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


/**
 * 提供事件数据服务
 * 用于检索事件列表
 * 用于获取事件详情
 */
@RestController
@RequestMapping("/eventdata")
@CrossOrigin    //允许跨域访问
public class EventDataController {

    @Resource
    private EventDataService service;

    //取得全部事件类型列表

    /**
     * 可以按照报警状态、事件类型、报警等级、工段、专业、接警人员、值班室、起止时间
     * 查询满足条件的报警事件。
     */
    @RequestMapping(value = "/selectEvents", method = RequestMethod.POST)
    public ResponseResult selectEvents(MyEvent myEvent, String begin, String end, @RequestParam("pageNo") int pageNo, @RequestParam("pageSize") int pageSize) {
        return service.selectEvents(myEvent, begin, end, pageNo, pageSize);
    }

    /**
     * 查询某值班室未处理事件的个数
     */
    @NeedRole("管理员||值班员")
    @RequestMapping(value = "/selectUnhandleEventCount", method = RequestMethod.POST)
    public ResponseResult selectUnhandleEventCount(@RequestParam("dutyRoomId") int dutyRoomId) {
        return service.selectUnhandleEventCount(dutyRoomId);
    }

    /**
     * 获取报警事件详情通过id
     *
     * @param id
     * @return
     */
    @RequestMapping(value = "/getEventDetail", method = RequestMethod.POST)
    public ResponseResult getEventDetail(@RequestParam int id) {
        return service.getEventDetail(id);
    }

    /**
     * 获取报警事件详情通过eventId
     *
     * @param eventId
     * @return
     */
    @RequestMapping(value = "/findEventDetail", method = RequestMethod.POST)
    public ResponseResult findEventDetail(@RequestParam String eventId) {
        return service.findEventDetail(eventId);
    }

    /**
     * 查询某个事件的处理流程进度条
     *
     * @param eventId
     * @return
     */
    @RequestMapping(value = "/findEventProcessBar", method = RequestMethod.POST)
    @ResponseBody
    public ResponseResult findEventProcessBar(@RequestParam String eventId) {
        return service.findEventProcessBar(eventId);
    }

    /**
     * 查询某个事件的全部处理流程记录
     *
     * @param eventId
     * @return
     */
    @RequestMapping(value = "/findEventProcessRecords", method = RequestMethod.POST)
    @ResponseBody
    public ResponseResult findEventProcessRecords(@RequestParam String eventId) {
        return service.findEventProcessRecords(eventId);
    }

    /**
     * 查询某个事件的处理人列表
     *
     * @param eventId
     * @return
     */
    @RequestMapping(value = "/findEventHandlers", method = RequestMethod.POST)
    @ResponseBody
    public ResponseResult findEventHandlers(@RequestParam String eventId) {
        return service.findEventHandlers(eventId);
    }

    /**
     * 获取报警图片
     * 用于测试海康平台给出的图片地址，图片会从海康平台下载到后端服务器本地文件夹
     * ！！！每次请求都会下载图片到本地文件夹！！！
     * @param uri
     * @return
     */
    @RequestMapping(value = "/getEventPic", method = RequestMethod.POST)
    public ResponseResult getEventPic(@RequestParam String uri) {
        return service.getEventPic(uri);
    }

    /**
     * 通过报警事件的主键id获取报警图片
     * 图片会从海康平台下载到后端服务器本地文件夹
     * ！！！每次请求都会下载图片到本地文件夹！！！
     * @param id
     * @return
     */
    @RequestMapping(value = "/getEventPicById", method = RequestMethod.POST)
    public ResponseResult getEventPicById(@RequestParam int id) {
        return service.getEventPicById(id);
    }

    /**
     * 通过报警事件的主键id获取报警图片
     * 推荐局域网下值班监控系统使用
     * 图片从海康平台请求，不会下载到后端服务器本地文件夹
     * @param id
     * @return
     */
    @RequestMapping(value = "/getEventPicFromHikiscById", method = RequestMethod.POST)
    public String getEventPicFromHikiscById(@RequestParam int id) {
        return service.getEventPicFromHikiscById(id);
    }

}
